package chapter05;

public class Java04_Object_String_02 {
    public static void main(String[] args) {
        // +频繁创建字符串占用内存空间×
        String s = "";
        for (int i = 0; i < 100; i++) {
            s = s + i;  //0123....
        }
        System.out.println(s);

        System.out.println("-----------------");

        // TODO StringBuilder
        // 构建字符串
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 100; i++) {
            sb.append(i);
        }
        System.out.println(sb);

        System.out.println("-----------------------");

        StringBuilder sb1 = new StringBuilder();
        sb1.append("abc");
        System.out.println(sb1.toString());
        System.out.println(sb1.length());   // 长度
        System.out.println(sb1.reverse());  // 反转
        System.out.println(sb1.insert(1,"d"));  // 插入
    }
}

